package com.pdg.dungeondelver.defaulttheme.renderers;

import org.newdawn.slick.Graphics;

import com.pdg.dungeondelver.client.constants.GameConstants;
import com.pdg.dungeondelver.client.constants.PropertyGroupConstants;
import com.pdg.dungeondelver.client.constants.UiConstants;
import com.pdg.dungeondelver.configuration.Configuration;
import com.pdg.dungeondelver.engine.Atlas;

public class DefaultLayerRenderer extends BaseRenderer{

	private Integer x=null;
	private Integer y=null;
	private Integer columnWidth=null;
	private Integer rowHeight=null;
	private Integer columns = null;
	private Integer rows = null;


	public DefaultLayerRenderer(Configuration configuration) {
		super(configuration);
	}
	
	public Integer getX(){
		if(x==null){
			x = getConfiguration().getPropertyGroups().get(PropertyGroupConstants.UI_CONSTANTS).<Integer>get(UiConstants.LAYER_RENDERER_X);
		}
		return x;
	}
	
	public Integer getY(){
		if(y==null){
			y = getConfiguration().getPropertyGroups().get(PropertyGroupConstants.UI_CONSTANTS).<Integer>get(UiConstants.LAYER_RENDERER_Y);
		}
		return y;
	}
	
	public Integer getColumnWidth(){
		if(columnWidth==null){
			columnWidth = getConfiguration().getPropertyGroups().get(PropertyGroupConstants.UI_CONSTANTS).<Integer>get(UiConstants.LAYER_RENDERER_COLUMN_WIDTH);
		}
		return columnWidth;
	}
	
	public Integer getRowHeight(){
		if(rowHeight==null){
			rowHeight = getConfiguration().getPropertyGroups().get(PropertyGroupConstants.UI_CONSTANTS).<Integer>get(UiConstants.LAYER_RENDERER_ROW_HEIGHT);
		}
		return rowHeight;
	}
	
	public Integer getColumns(){
		if(columns==null){
			columns = getConfiguration().getPropertyGroups().get(PropertyGroupConstants.GAME_CONSTANTS).<Integer>get(GameConstants.LAYER_COLUMNS);
		}
		return columns;
	}
	
	public Integer getRows(){
		if(rows==null){
			rows = getConfiguration().getPropertyGroups().get(PropertyGroupConstants.GAME_CONSTANTS).<Integer>get(GameConstants.LAYER_ROWS);
		}
		return rows;
	}
	

	@Override
	public void render(Graphics g,Atlas atlas) {
		for(Integer column=0;column<getColumns();++column){
			for(Integer row=0;row<getRows();++row){
				Integer cellX = getX()+getColumnWidth()*column;
				Integer cellY = getY()+getRowHeight()*row;
				g.drawRoundRect(cellX, cellY, getColumnWidth(), getRowHeight(), getRowHeight()/4);
			}
		}
	}

}
